﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using OnlineTestBLL;
using OnlineTestModel;

namespace OnlineTestUI.BackManager
{
    public partial class updatestudent : System.Web.UI.Page
    {
        StudentsBLL sb = new StudentsBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    int id = Convert.ToInt32(Request.QueryString["id"]);
                    Students oldt = new Students();
                    oldt = sb.GetModel(id);
                    tbRealName.Text = oldt.RealName;
                    tbUserName.Text = oldt.UserName;
                    
                   
                    tbDescription.Text = oldt.Description;
                    
                    tbRoleList.Text = oldt.RoleList;
                    lCreateTime.Text = oldt.CreateTime.ToString("d");
                    ddlStatus.SelectedValue = oldt.Status.ToString() ;
                }
            }
        }
        protected void BtAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                Students s = new Students();
                s.RealName = tbRealName.Text;
                s.UserName = tbUserName.Text;
                //如果密码不为空，说明要修改密码
                if (!string.IsNullOrEmpty(tbPassWord.Text))
                {
                    s.PassWord = tbPassWord.Text;
                }
                s.Description = tbDescription.Text;
                s.RoleId = Convert.ToInt32(1);
                s.RoleList = tbRoleList.Text;
                //s.CreateId = ((Teachers)Session["Teacher"]).Id;
                //学生状态
                s.Status = Convert.ToInt32(ddlStatus.SelectedValue);
                s.Id=Convert.ToInt32(Request.QueryString["id"]);
                s.ClassId = 1;
                bool result = sb.Update(s);
                if (result)
                {
                    PageContext.Redirect("Studentlist.aspx", "_self");
                }
            }
        }
    }
}